package java8Test.function.lambda;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import spring.po.User;

public class TrUpdateImpl<T> extends AbstractTrUpdate<T, SFunction<T, ?>> {

    public static <T> TrUpdateImpl<T> lambda() {
        return new TrUpdateImpl();
    }

    @Override
    public void update(SFunction<T, ?> func) {
        Field[] declaredFields = func.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            System.out.println(field.getName());
        }
    }

    @Override
    public void update(T t, SFunction<T, ?> func) {
//        if (func instanceof Proxy) {
            InvocationHandler handler = Proxy.getInvocationHandler(func);
            try {
                Field val$target = handler.getClass().getDeclaredField("val$target");
                System.out.println(val$target.get(t));
            } catch (NoSuchFieldException | IllegalAccessException e) {
                e.printStackTrace();
            }
//        }
    }
}
